﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using Model;

namespace DAL
{
   public class TruckDAL
    {
        public static List<Model.Truck> GetAllTruck()
        {
            string sql = "select * from Truck where IsDelete=0";
            SqlDataReader reader = DBHelper.ExecuteReader(sql); 
            List<Model.Truck> lst = new List<Model.Truck>();
            while (reader.Read())
            {
                Model.Truck truck = new Truck();

                truck.TruckID = Convert.ToInt32(reader["TruckID"]);
                truck.Number = reader["Number"].ToString();
                truck.BuyDate = Convert.ToDateTime(reader["BuyDate"]);
                truck.Type = reader["Type"].ToString();
                truck.Length = reader["Length"].ToString();
                truck.Tonnage = Convert.ToInt32(reader["Tonnage"]);
                truck.State = Convert.ToInt32(reader["State"]);
                truck.Remark = reader["Remark"].ToString();
                truck.CheckInTime = Convert.ToDateTime(reader["CheckInTime"]);
                truck.AlterTime = Convert.ToDateTime(reader["AlterTime"]);
                truck.TeamName =reader["FK_TeamID"].ToString();
                lst.Add(truck);
            }
            return lst;
        
        }
        public static int delete(string truckID)
        {
            string sql = "update Truck set IsDelete=1 where truckID=@truckId";
            SqlParameter[] paras = new SqlParameter[]
            {
                new SqlParameter("@truckId",truckID)
            };
            return DBHelper.ExecuteNonQuery(sql,System.Data.CommandType.Text,paras);
        }
        
    }
}
